package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BedInfo;
import com.ruoyi.system.service.IBedInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 床位信息Controller
 */
@RestController
@RequestMapping("/system/bed")
public class BedInfoController extends BaseController {
    @Autowired
    private IBedInfoService bedInfoService;

    @GetMapping()
    public String bed() {
        return "system/bed/index";
    }

    /**
     * 查询床位信息列表
     */
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody BedInfo bedInfo) {
        startPage();
        List<BedInfo> list = bedInfoService.selectBedInfoList(bedInfo);
        return getDataTable(list);
    }

    /**
     * 导出床位信息列表
     */
    @Log(title = "床位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(@RequestBody BedInfo bedInfo) {
        List<BedInfo> list = bedInfoService.selectBedInfoList(bedInfo);
        ExcelUtil<BedInfo> util = new ExcelUtil<BedInfo>(BedInfo.class);
        return util.exportExcel(list, "床位信息数据");
    }

    /**
     * 新增床位信息
     */
    @GetMapping("/add")
    public String add() {
        return "system/bed/add";
    }

    /**
     * 新增保存床位信息
     */
    @Log(title = "床位信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addSave(@RequestBody BedInfo bedInfo) {
        return toAjax(bedInfoService.insertBedInfo(bedInfo));
    }

    /**
     * 获取床位信息详细信息
     */
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bedInfoService.selectBedInfoById(id));
    }

    /**
     * 修改保存床位信息
     */
    @Log(title = "床位信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult editSave(@RequestBody BedInfo bedInfo) {
        return toAjax(bedInfoService.updateBedInfo(bedInfo));
    }

    /**
     * 删除床位信息
     */
    @Log(title = "床位信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody String ids) {
        return toAjax(bedInfoService.deleteBedInfoByIds(new Long[]{Long.parseLong(ids.replaceAll("[^0-9]", ""))}));
    }
}  